<template>
  <div class="layout">
    <div class="top-wrap">
      <el-radio-group v-model="materialId">
        <el-radio-button label="1">基础素材</el-radio-button>
        <el-radio-button label="2">朋友圈素材</el-radio-button>
      </el-radio-group>
      <div class="text" v-if="materialId == 1">仅统计开启雷达的内容，数据每小时更新一次，上次更新时间：{{ update ? update.split(' ')[1] : '暂无' }}</div>
      <div class="text" v-else>数据每小时更新一次，上次更新时间：{{ update ? update.split(' ')[1] : '暂无' }}</div>
    </div>

    <StatisticsSearch :options="statisOptions" @submit="onSubmit" />
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive, computed, watch, onMounted, nextTick } from 'vue'
  import type { ElForm } from 'element-plus'
  import { getDay, DFormat } from '@/utils/utils'
  import StatisticsSearch from '@/components/zw/statistics-search/StatisticsSearch.vue'
  import { useStore } from '@/store'
  type FormInstance = InstanceType<typeof ElForm>
  const emit = defineEmits({
    submit: null,
    changeLabel: null
  })
  const props = defineProps(['weChart', 'update'])
  interface TAGSINFO {
    TagsVisble: boolean // 标签弹框,
    showCreatTag?: boolean // 是否新建标签
  }
  const store = useStore()

  const selecDialogRef = ref(null)
  const DepartRef = ref(null)
  const formRef = ref<FormInstance>()
  const materialId = ref(1) // 素材选择
  // 创建人options
  const creators = ref([
    {
      value: '',
      label: '全部'
    },
    {
      value: 2,
      label: '图片'
    },
    {
      value: 3,
      label: '音频'
    },
    {
      value: 4,
      label: '视频'
    },
    {
      value: 5,
      label: '文件'
    },
    {
      value: 6,
      label: '链接'
    }
  ])
  // 类型
  const type = ref(1)
  // 标签
  const formItem = reactive([
    {},
    {
      derpartLabel: '素材类型',
      timeLabel: '时间筛选'
    }
  ])
  // 收集的表单数据
  const form = reactive({
    users: '',
    filter_time: [],
    currentId: '2'
  })
  const statisOptions = computed(() => {
    const arr = [
      {
        label: '素材类型',
        type: 'select',
        key: 'hobby',
        placeholder: '全部',
        optionList: creators.value
      },
      {
        label: '时间筛选',
        type: 'dateFilter',
        currentId: 1
      },
    ]
    if(materialId.value == 2) {
      arr.splice(0,1)
    }
    return arr
  })
  const onSubmit = (data:any) => {
    form.users = data.hobby
    form.filter_time = data.times || []
    nextTick(() => {
      if(data.times) {
        emit('submit', form)
      }
    })
  }
  // 素材筛选
  const filterMaterial = (event: any) => {
    materialId.value = event.target.id
    emit('changeLabel', materialId.value)
  }
  //重置
  const resetForm = () => {
    form.keyword = ''
    form.users = ''
    form.date1 = getDay(-6)
    form.date2 = getDay(0, true)
    form.type = ''
    form.currentId = '2'
    submitForm()
  }
  const changeDate = () => {
    form.currentId = ''
  }

  watch(materialId, (v) => {
    materialId.value = v
    emit('changeLabel', v)
  })
</script>

<style lang="scss" scoped>
  .layout {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .top-wrap {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .top {
      display: flex;
      margin-bottom: 20px;
      &_btn {
        padding: 10px 21px;
        background: #ffffff;
        border: 1px solid #ff6b00;
        font-size: 16px;
        color: #ff6b00;
        line-height: 16px;
        cursor: pointer;
      }
      .active {
        background: #ff6b00;
        color: #ffff;
      }
    }
    .searchForm {
      display: flex;
      // justify-content: space-between;
      border: 1px solid #eaeaea;
      align-items: center;
      margin-top: 16px;
      padding: 24px 16px 0;
      background: #fff;
      position: relative;
      .search_item {
        max-width: 180px;
        margin-bottom: 0;
      }
      .selectTime {
        .selectTime_btn {
          display: flex;
          align-items: center;
          &_item {
            padding: 0 10px;
            margin-right: 16px;
            background: #ffffff;
            border-radius: 4px;
            border: 1px solid #eaeaea;
            cursor: pointer;
          }
          .active {
            border: 1px solid #ff6b00;
            color: #ff6b00;
          }
        }
        :deep(.el-form-item__content) {
          display: flex;
          align-items: center;
          .text-center {
            min-width: 14px;
            margin: 0 13px;
            border-top: 1px solid #969696;
          }
          .el-date-editor {
            width: 200px !important;
          }
        }
      }
      .search_btn {
        position: absolute;
        top: 5px;
        right: 0;
      }
    }
    .text {
      font-size: 14px;
      color: #848484;
    }
  }
</style>
